package com.iceclean.util;

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
 * @author : Ice'Clean
 * @date : 2021-05-14
 *
 * 日志管理类
 */
public class MyLogger {
    Logger logger = Logger.getLogger("MyLogger");
    FileHandler fileHandler;

    /**
     * 初始化日志
     * @param logName 日志文件的名称
     */
    public MyLogger(String logName) {
        try {
            fileHandler = new FileHandler("D:/1_IceCleanDevelop/2_Java/1_Java_Practices/3 ~ JavaWeb/QG_Tieba/out/artifacts/QG_Tieba_war_exploded/log/" + logName + ".log", true);
            logger.addHandler(fileHandler);

            SimpleFormatter formatter = new SimpleFormatter();
            fileHandler.setFormatter(formatter);
        } catch (SecurityException | IOException e) {
            e.printStackTrace();
        }
    }

    public void writeInfo(String message) {
        logger.info(message);
    }

}
